/*
 * @Description: 自定义字段
 * @Author: june
 */
import request from "@/utils/request";

// 新增
export function customFieldSave(customFieldAddDTO) {
  return request({
    url: "/config/api/v1/customFields",
    method: "post",
    data: customFieldAddDTO
  });
}

// 修改
export function customFieldUpdate(customFieldUpdateDTO) {
  return request({
    url: "/config/api/v1/customFields",
    method: "put",
    data: customFieldUpdateDTO
  });
}

// 单个删除
export function customFieldDelete(customFieldId) {
  return request({
    url: `/config/api/v1/customFields/${customFieldId}`,
    method: "delete"
  });
}

// 批量删除
export function customFieldDeleteBatch(customFieldIds) {
  return request({
    url: "/config/api/v1/customFields",
    method: "delete",
    data: customFieldIds
  });
}

// 根据id查找
export function customFieldFindById(customFieldId) {
  return request({
    url: `/config/api/v1/customFields/${customFieldId}`,
    method: "get"
  });
}

// 查找所有
export function customFieldListAll(customFieldQuery) {
  return request({
    url: "/config/api/v1/customFields/listAll",
    method: "get",
    params: customFieldQuery
  });
}

// 分页查询
export function customFieldPage(customFieldQuery) {
  let ordersParam = "";
  if (customFieldQuery.orders) {
    customFieldQuery.orders.forEach((order, index) => {
      const op = "orders[" + index + "]";
      if (ordersParam !== "") {
        ordersParam += "&";
      }
      ordersParam += op + ".property=" + order.property + "&" + op + ".desc=" + order.desc;
    });
    customFieldQuery.orders = undefined;
  }
  return request({
    url: "/config/api/v1/customFields?" + ordersParam,
    method: "get",
    params: customFieldQuery
  });
}
